package com.mxnet.chongjin.nci.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mxnet.chongjin.nci.R;
import com.mxnet.chongjin.nci.bean.Cause;

import java.util.List;

/**
 * author:chongjin
 * email:lcj270018655@163.com
 * date:2018/10/26
 * other:
 */

public class CauseAdapter extends BaseAdapter {
    private Context mContext;
    private List<Cause> mCauseList;

    public CauseAdapter(Context context, List<Cause> causeList) {
        mContext = context;
        mCauseList = causeList;
    }

    @Override
    public int getCount() {
        return mCauseList.size();
    }

    @Override
    public Object getItem(int position) {
        return mCauseList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_cause_spinner, parent, false);
            viewHolder.mTextView = convertView.findViewById(R.id.textview_item_cause_spinner);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.mTextView.setText(mCauseList.get(position).getDescribe());

        return convertView;
    }

    public static class ViewHolder {
        TextView mTextView;
    }
}
